package com.yhj.servlet.container;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class HttpTomcat {
	
	private int port=8888;

	public static void main(String[] args) {
		HttpTomcat tomcat=new HttpTomcat();
		tomcat.startServer();
	}
	
	public void startServer(){
		ServerSocket ss=null;
		try {
			// 其实就是一个套接字的服务器
			ss=new ServerSocket(port);
			System.out.println("服务器开启");
		} catch (IOException e) {
			e.printStackTrace();
		}
		while(true){//为了满足多个网站的访问，这里设计为一个死循环，并且在每一次接收到socket之后，开启一个新的线程来处理这个请求
			Socket s;
			try {
				s = ss.accept();
				Thread t=new Thread(new ServerService(s));//把接收到的Socket传到ServerService中，它实现了Runnable接口
				t.start();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
